import logging

import ddddocr
from PIL import Image
import base64
from io import BytesIO


def dddd_ocr_text(image_data):
    logging.info("======================开始执行验证码识别函数================================")
    logging.info(f"当前识别的图片数据:{image_data}")
    new_data = image_data.split(",")[1]
    decode_data = base64.b64decode(new_data)
    image = Image.open(BytesIO(decode_data))
    bytes_io = BytesIO()
    image.save(bytes_io,format="PNG")
    image_bytes = bytes_io.getvalue()
    ocr = ddddocr.DdddOcr()
    code = ocr.classification(image_bytes)
    logging.info("======================验证码识别函数执行完毕================================")
    return code


